<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "project_smi".
 *
 * @property int $id
 * @property string $title
 * @property string|null $url
 * @property string|null $date_published
 * @property int|null $id_project
 *
 * @property Project $project
 */
class ProjectSmi extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'project_smi';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['title'], 'required'],
            [['date_published'], 'safe'],
            [['id_project'], 'integer'],
            [['title', 'source_name'], 'string', 'max' => 512],
            [['url'], 'string', 'max' => 1024],
            [['id_project'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['id_project' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => 'Название',
            'source_name' => 'Источник',
            'url' => 'URL',
            'date_published' => 'Дата публикации',
            'id_project' => 'Проект',
        ];
    }

    /**
     * Gets query for [[Project]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getProject()
    {
        return $this->hasOne(Project::className(), ['id' => 'id_project']);
    }
}
